package com.traceability.trace.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.traceability.common.annotation.Log;
import com.traceability.common.core.controller.BaseController;
import com.traceability.common.core.domain.AjaxResult;
import com.traceability.common.enums.BusinessType;
import com.traceability.trace.domain.Environmentmonitoring;
import com.traceability.trace.service.IEnvironmentmonitoringService;
import com.traceability.common.utils.poi.ExcelUtil;
import com.traceability.common.core.page.TableDataInfo;

/**
 * 生产地环境监测Controller
 * 
 * @author xulin
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/traceability-trace/environmentmonitoring")
public class EnvironmentmonitoringController extends BaseController
{
    @Autowired
    private IEnvironmentmonitoringService environmentmonitoringService;

    /**
     * 查询生产地环境监测列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:environmentmonitoring:list')")
    @GetMapping("/list")
    public TableDataInfo list(Environmentmonitoring environmentmonitoring)
    {
        startPage();
        List<Environmentmonitoring> list = environmentmonitoringService.selectEnvironmentmonitoringList(environmentmonitoring);
        return getDataTable(list);
    }

    /**
     * 导出生产地环境监测列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:environmentmonitoring:export')")
    @Log(title = "生产地环境监测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Environmentmonitoring environmentmonitoring)
    {
        List<Environmentmonitoring> list = environmentmonitoringService.selectEnvironmentmonitoringList(environmentmonitoring);
        ExcelUtil<Environmentmonitoring> util = new ExcelUtil<Environmentmonitoring>(Environmentmonitoring.class);
        util.exportExcel(response, list, "生产地环境监测数据");
    }

    /**
     * 获取生产地环境监测详细信息
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:environmentmonitoring:query')")
    @GetMapping(value = "/{monitoringId}")
    public AjaxResult getInfo(@PathVariable("monitoringId") Long monitoringId)
    {
        return success(environmentmonitoringService.selectEnvironmentmonitoringByMonitoringId(monitoringId));
    }

    /**
     * 新增生产地环境监测
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:environmentmonitoring:add')")
    @Log(title = "生产地环境监测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Environmentmonitoring environmentmonitoring)
    {
        return toAjax(environmentmonitoringService.insertEnvironmentmonitoring(environmentmonitoring));
    }

    /**
     * 修改生产地环境监测
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:environmentmonitoring:edit')")
    @Log(title = "生产地环境监测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Environmentmonitoring environmentmonitoring)
    {
        return toAjax(environmentmonitoringService.updateEnvironmentmonitoring(environmentmonitoring));
    }

    /**
     * 删除生产地环境监测
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:environmentmonitoring:remove')")
    @Log(title = "生产地环境监测", businessType = BusinessType.DELETE)
	@DeleteMapping("/{monitoringIds}")
    public AjaxResult remove(@PathVariable Long[] monitoringIds)
    {
        return toAjax(environmentmonitoringService.deleteEnvironmentmonitoringByMonitoringIds(monitoringIds));
    }

}
